package avicit.im.lantop.archiveclassmanager.service.api;

import avicit.platform6.commons.utils.web.TreeNode;
import avicit.platform6.core.rest.msg.ResponseMsg;
import avicit.platform6.core.restclient.RestClient;
import avicit.platform6.core.restclient.RestClientUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class ArchiveClassManagerIntfsServiceApi {


    /**
     * 服务编码
     */
    private static final String SERVICE_CODE = "filebasicmanager";

    private static final String BASE_PATH = "/api/avicit/im/lantop/basic/libstructuredefine/action/rest/LantopArchiveRest";

    @Autowired
    private RestClient restClient;


    /**
     * 删除文件管理冗余树节点数据
     * @param orgId
     * @param deptId
     * @param sysId
     * @param param
     */
    public void deleteRedundancyTreeData(String orgId, String deptId, String sysId, Map<String, Object> param) {
        String url = BASE_PATH + "/deleteRedundancyTreeData";
        Map<String,Object> map = new HashMap<>();
        map.put("orgId",orgId);
        map.put("deptId",deptId);
        map.put("sysId",sysId);
        map.put("param",param);
        ResponseMsg responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<T>>() {
        });
    }

    /**
     * 获取档案分类树信息：树形展示（文件夹、模板、数据节点、物理表）
     * @param org_root
     * @param s
     * @return
     */
    public List<TreeNode> getArchiveClassTreeNodeToTableInfoByIntfs(String org_root, String s) {
        String url = BASE_PATH + "/getArchiveClassTreeNodeToTableInfoByIntfs";
        Map<String,Object> map = new HashMap<>();
        map.put("org_root",org_root);
        map.put("s",s);
        ResponseMsg<List<TreeNode>> responseMsg = restClient.doPost(SERVICE_CODE, url,  new ParameterizedTypeReference<ResponseMsg<List<TreeNode>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     * 获取选中节点和节点下子节点数据
     * @param orgId
     * @param deptId
     * @param sysId
     * @param targetNodeId
     * @return
     */
    public List<Map<String, Object>> getSelectNodeChild(String orgId, String deptId, String sysId, String targetNodeId) {
        String url = BASE_PATH + "/getSelectNodeChild/v1";
        Map<String,Object> map = new HashMap<>();
        map.put("orgId",orgId);
        map.put("deptId",deptId);
        map.put("sysId",sysId);
        map.put("targetNodeId",targetNodeId);
        ResponseMsg<List<Map<String, Object>>> responseMsg = restClient.doPost(SERVICE_CODE, url,  new ParameterizedTypeReference<ResponseMsg<List<Map<String, Object>>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }
}
